package com.rraj.common.mq.test;

import javax.annotation.Resource;

import com.xiaoleilu.hutool.date.DateUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by WangSheng on 2017/6/9.
 *
 * @author WangSheng
 * @date 2017/06/09
 */
@RestController
public class MQTestController {
    @Resource
    private MQTestService testService;
    /**
     * 同步发送普通消息
     */
    @RequestMapping("/sendCommonMessageSync")
    public String sendCommonMessageSync() throws Exception {
        long time = DateUtil.current(false);
        return testService.sendCommonMessageSync()?"同步发送普通消息成功!耗时：" + (DateUtil.current(false) - time):"同步发送普通消息失败!";
    }

    /**
     * 异步发送普通消息
     */
    @RequestMapping("/sendCommonMessageAsync")
    public String sendCommonMessageAsync() throws Exception {
        long time = DateUtil.current(false);
        return testService.sendCommonMessageAsync()?"异步发送普通消息成功!耗时：" + (DateUtil.current(false) - time):"异步发送普通消息失败!";
    }

    /**
     * 单向发送普通消息
     */
    @RequestMapping("/sendCommonMessageOneway")
    public String sendCommonMessageOneway() throws Exception {
        long time = DateUtil.current(false);
        return testService.sendCommonMessageOneway()?"单向发送普通消息成功!耗时：" + (DateUtil.current(false) - time):"单向发送普通消息失败!";
    }

    /**
     * 发送定时消息
     */
    @RequestMapping("/sendTimingMessage")
    public String sendTimingMessage() throws Exception {
        long time = DateUtil.current(false);
        return testService.sendTimingMessage()?"发送定时消息成功!耗时：" + (DateUtil.current(false) - time):"发送定时消息失败!";
    }

    /**
     * 发送延时消息
     */
    @RequestMapping("/sendDelayMessage")
    public String sendDelayMessage() throws Exception {
        long time = DateUtil.current(false);
        return testService.sendDelayMessage()?"发送延时消息成功!耗时：" + (DateUtil.current(false) - time):"发送延时消息失败!";
    }

    /**
     * 发送事务消息
     */
    @RequestMapping("/sendTransactionMessage")
    public String sendTransactionMessage() throws Exception {
        long time = DateUtil.current(false);
        return testService.sendTransactionMessage()?"发送事务消息成功!耗时：" + (DateUtil.current(false) - time):"发送事务消息失败!";
    }

    /**
     * 发送全局顺序消息
     */
    @RequestMapping("/sendOrderAllMessage")
    public String sendOrderAllMessage() throws Exception {
        long time = DateUtil.current(false);
        return testService.sendOrderAllMessage()?"发送全局顺序消息成功!耗时：" + (DateUtil.current(false) - time):"发送全局顺序消息失败!";
    }

    /**
     * 发送分区顺序消息
     */
    @RequestMapping("/sendOrderShardingMessage")
    public String sendOrderShardingMessage() throws Exception {
        long time = DateUtil.current(false);
        return testService.sendOrderShardingMessage()?"发送分区顺序消息成功!耗时：" + (DateUtil.current(false) - time):"发送分区顺序消息失败!";
    }
}
